package cn.xqj.user.controller;

import cn.xqj.basic.exception.BusinessException;
import cn.xqj.basic.util.AjaxResult;
import cn.xqj.user.dto.EmailUserDto;
import cn.xqj.user.dto.UserDto;
import cn.xqj.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private IUserService userServiceImpl;

    @PostMapping("/register/phone")
    public AjaxResult phoneRegiser(@RequestBody UserDto userDto) {
        try {
            userServiceImpl.phoneRegiser(userDto);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("服务器繁忙，请稍后再试");
        }

    }

    @PostMapping("/register/email")
    public AjaxResult emailRegiser(@RequestBody EmailUserDto emailUserDto) {
        try {
            userServiceImpl.emailRegiser(emailUserDto);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("服务器繁忙，请稍后再试");
        }

    }




}
